package grafica.ventanas;

import grafica.controladores.ControladorEmpleadosListado;
import grafica.controladores.ControladorEmpresasSelect;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JComboBox;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import logica.datatypes.DataEmpresa;
import grafica.ventanas.EmpleadosListado;

public class empresasSelect {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="243,28"
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JComboBox jComboBox = null;
	private JButton jButton = null;
	private DataEmpresa[] Empresas ;
	private int [] IdEmpresas;
	private ControladorEmpresasSelect ConEmpleadoListado;
	private int rut;
	private JButton jButton1 = null;
	
	
	/*public empresasSelect() {
		// TODO Auto-generated constructor stub
	}*/

	public empresasSelect() {
		ConEmpleadoListado = new ControladorEmpresasSelect(this);
		
	}
	/**
	 * This method initializes jFrame	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setSize(new Dimension(341, 172));
			jFrame.setTitle("Seleccione Empresa");
			jFrame.setContentPane(getJContentPane());
			jFrame.setLocationRelativeTo(null);	
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanel(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.gridx = 1;
			gridBagConstraints11.gridy = 1;
			gridBagConstraints11.insets = new Insets(10,10,10,10);
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 0;
			gridBagConstraints1.gridy = 1;
			gridBagConstraints1.insets = new Insets(10,10,10,10);
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.gridx = 0;
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.add(getJComboBox(), gridBagConstraints);
			jPanel.add(getJButton(), gridBagConstraints1);
			jPanel.add(getJButton1(), gridBagConstraints11);
		}
		return jPanel;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			int cant = 0;
			jComboBox = new JComboBox();	
			jComboBox.setPreferredSize(new java.awt.Dimension(180,25));
			////Completra, Cargar empresas existentes en base
			Empresas = ConEmpleadoListado.getEmpreas();
			cant = Empresas.length;
			IdEmpresas = new int[cant];
			
			
			for (int i=0; i<cant; i++){	
				jComboBox.addItem(Empresas[i].getRazon_Social());	
				IdEmpresas[i] = Empresas[i].getRut();
		   }
		}
			
		return jComboBox;
		}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("VER EMPLEADOS");
			ActionListener Button = new ActionListener(){
				public void actionPerformed (ActionEvent e){ 
					rut = IdEmpresas[jComboBox.getSelectedIndex()];
					
					EmpleadosListado empListado = new EmpleadosListado(rut);
		        	empListado.setVisible(true);
				}
			};
			jButton.addActionListener(Button);
			
		}
		return jButton;
	}
	
	public void setVisible (boolean b){	
		this.getJFrame().setVisible(b);
	}
	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Cerrar");
			ActionListener BotonCancelar = new ActionListener(){
				public void actionPerformed (ActionEvent e){ 				
					jFrame.dispose();				
				}
			};
			jButton1.addActionListener(BotonCancelar );
		}
		return jButton1;
	}

}
